package com.sharing.controller;

import com.sharing.common.Page;
import com.sharing.common.Result;
import com.sharing.domain.Hobby;
import com.sharing.domain.ProductionHobby;
import com.sharing.domain.dto.ProductionDto;
import com.sharing.service.ProductionHobbyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author MingTian
 * @version 1.0
 * @description TODO
 * @date 2023/4/3 10:29
 */
@RestController
@RequestMapping("/productionHobby")
public class ProductionHobbyController {
    @Autowired
    private ProductionHobbyService productionHobbyService;

    /**
     * 根据作品Id查询用户的兴趣
     * @param productionId
     * @return
     */
    @GetMapping("/productionId")
    public Result<Page<Hobby>> selectHobbyByUserId(Integer productionId, Integer level, Integer page, Integer size) {
        return productionHobbyService.selectHobbyByProductionId(productionId, level, page, size);
    }

    /**
     * 根据兴趣查询作品基本信息
     * @param hobbies
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/productions")
    public Result<Page<ProductionDto>> selectProductionDtoByHobby(@RequestParam List<String> hobbies, Integer page, Integer size) {
        return productionHobbyService.selectProductionDtoByHobby(hobbies, page, size);
    }


    /**
     * 新增作品对应兴趣————单个
     * @param productionHobby
     * @return
     */
    @PostMapping
    public Result<ProductionHobby> insertHobby(@RequestBody ProductionHobby productionHobby) {
        return productionHobbyService.insertHobby(productionHobby);
    }

    /**
     * 新增作品对应兴趣————多个
     * @param productionHobbies
     * @return
     */
    @PostMapping("/mult")
    public Result<Integer> insertHobbies(@RequestBody List<ProductionHobby> productionHobbies) {
        return productionHobbyService.insertHobbies(productionHobbies);
    }

    /**
     * 删除作品对应兴趣————多个
     * @param hobbyIds
     * @param productionId
     * @return
     */
    @DeleteMapping("/mult")
    public Result<Integer> deleteHobbies(@RequestParam List<Integer> hobbyIds, Integer productionId) {
        return productionHobbyService.deleteHobbies(hobbyIds, productionId);
    }
}
